/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package operators;

import metadata.IndexMetaData;
import metadata.TableMetaData;

/**
 *
 * @author Dragan
 */
public class IndexAccess extends Operation {

    protected TableMetaData tableMetaData;
    protected IndexMetaData indexMetaData;
    protected long inputSize;

    public IndexAccess(TableMetaData tableMetaData, IndexMetaData indexMetaData, long inputSize) {
        this.tableMetaData = tableMetaData;
        this.indexMetaData = indexMetaData;
        this.inputSize = inputSize;
        this.operationName = "IndexAccess";
        execute();
    }

    @Override
    protected void execute() {
        diskCost = inputSize * indexMetaData.getHeightOfBPlusTree() + 1 + indexMetaData.getDiskPagesToStoreABitmap();
        outputSize = (inputSize * tableMetaData.getNumberOfTuples()) / indexMetaData.getDistinctKeyValues();
    }

    @Override
    public String toString() {
        String str = " t:" + tableMetaData.getTableName() + " input:" + this.inputSize;
        return this.operationName + str + " " + super.toString();
    }
}
